import { createRouter, createWebHistory } from 'vue-router'
import routes from './routers'
import whiteList from './whiteList'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: routes
})

router.beforeEach((to, from, next) => {
  // 如果不包含白名单和未登录的状态，就路由拦截跳转到Login页面
  if ((whiteList.indexOf(to.name as string) == -1) && !localStorage.getItem('token')) {
    next({ name: 'Login' })
  }
  // 如果符合条件就放行
  else next()
})


export default router
